<template>
  <div>
    <MyHeader title="购物车案例" background="orange"></MyHeader>
    <div class="main">
      <MyGoods v-for="item in list" :key="item.id" :item="item"></MyGoods>
    </div>
    <MyFooter @changeAll="changeAllFn" :list="list"></MyFooter>
  </div>
</template>

<script>
import MyGoods from "./components/MyGoods.vue";
import MyFooter from "./components/MyFooter.vue";
import MyHeader from "./components/MyHeader.vue";
export default {
  components: {
    MyGoods,
    MyFooter,
    MyHeader,
  },
  data() {
    return {
      list:[]
    }
  },
  created () {
    this.$axios({
      url: '/api/cart',
    }).then(res => {
      this.list = res.data.list
    })
  },
  methods: {
    changeAllFn(val) {
      this.list.forEach(item => item.goods_state = val)
    }
  }
};
</script>

<style scoped>
  .main{
    padding-top: 45px;
    padding-bottom: 50px;
  }
</style>
